import { WorkerChannel } from "../worker.channel";
import { WorkerBaseController } from "./worker.controller";

export class WorkerThreadController extends WorkerBaseController {
    public constructor() {
        super();

        // Worker 线程中的全局环境 self 就是 Worker 实例
        this.worker = self as any;
        this.channel = new WorkerChannel(this.worker, {
            actionHandler: this.actionHandler.bind(this),
        });
    }

    protected reportActionHandlerError(actionType: string, error: any): void {
        console.error(`Worker aciton ${actionType}:`, error);

        // 正常抛出
        throw new Error(error);
    }
}
